package com.quanyan.stadiumScheduler.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by wanglei on 2016/6/12.
 */
public class DateUtil {

    public static boolean isEmpty(String param) {

        return param == null || param.equals("");

    }

    public static boolean isEmpty(String... params) {

        for (String param : params) {
            if (param == null || param.trim().equals("")) {
                return true;
            }
        }

        return false;
    }

    public static boolean isNotEmpty(String param) {
        return !isEmpty(param);
    }

    public static boolean isNotEmpty(String... params) {

        for (String param : params) {
            if (param == null || param.trim().equals("")) {
                return false;
            }
        }

        return true;
    }

    public static String stringNullChange(String param) {
        return isEmpty(param) ? "" : param;
    }

    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm";

    @SuppressWarnings("rawtypes")
    private static ThreadLocal threadLocal = new ThreadLocal() {
        protected synchronized Object initialValue() {
            return new SimpleDateFormat(DATE_FORMAT);
        }
    };

    public static DateFormat getDateFormat() {
        return (DateFormat) threadLocal.get();
    }

    public static Date parse(String textDate) throws ParseException {
        return getDateFormat().parse(textDate);
    }

    public static String deParse(Date date){
        return getDateFormat().format(date);
    }

    public static String getSpecialDateStr(){
        return "[" + getDateFormat().format(new Date()) + "]";
    }

}
